/*
useage:valite whether the string is suitable the patten	
str:be valite string;
ptn:valite patten;
iddesc:whether valite the data from Positive
*/
function sysValite(str,ptn,isdesc)
{
	var patten=new RegExp(ptn);
	if(isdesc==1)
	{
		if(!patten.test(str))
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		if(!patten.test(str))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
function isDate(str)
{
	return sysValite(str,/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/,1);
	/*var ptn=/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
	if(!ptn.test(str))
		{
			return false;
		}
		else
		{
			return true;
		}*/
}
function isTel(str)
{
	return sysValite(str,/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)/,1);
}
function isMobile(str)
{
	return sysValite(str,/(^0{0,1}15[0-9]{9}$)|(^0{0,1}13[0-9]{9}$)/,1);
}
function isPhone(str)
{
	return sysValite(str,/(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}15[0-9]{9}$)|(^0{0,1}13[0-9]{9}$)/,1);
}
function isZipCode(str)
{
	return sysValite(str,/^[1-9]\d{5}$/,1);
}
function isEmail(str)
{
	return sysValite(str,/^\w+([-+.]\w+)*@\w+([-.]\\w+)*\.\w+([-.]\w+)*$/,1);
}
function isIdCard(str)
{
	return sysValite(str,/^\d{15}(\d{2}[A-Za-z0-9])?$/,1);
}
function isChinese(str)
{
	return sysValite(str,/^[\u0391-\uFFE5]+$/,1);
}
function isQQ(str)
{
	return sysValite(str,/^[1-9]\d{4,8}$/,1);
}
function isBlank(id)
{
	if(document.getElementById(id).value==""||document.getElementById(id).value.length==0)
	{
		return true;
	}
	else
	{
		if(trim(document.getElementById(id).value).length==0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
function isNo(id)
{
	if(isNaN(document.getElementById(id).value))
	{
		return false;
	}
	else
	{
		return true;
	}
}
function isInt(num)
{
	if(isNo(num))
	{
		return (document.getElementById(num).value%1)==0?true:false;
	}
	else
	{
		return false;
	}
}
function isFloat(num)
{
	if(isNo(num))
	{
		return (document.getElementById(num).value%1)!=0?true:false;
	}
	else
	{
		return false;
	}
}
function setFocus(el)
{
	$(el).focus();
}
function clearVal(el)
{
	$(el).value="";
}
function trim(inputString) {
	if (typeof inputString != 'string')
		return inputString;
    var retValue = inputString, ch = retValue.substring(0, 1);
    while(ch == ' ' || ch == '\r' || ch == '\n') {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length-1, retValue.length);
    while(ch == ' ' || ch == '\r' || ch == '\n') {
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
    }
    while(retValue.indexOf('  ') != -1) {
		retValue = retValue.substring(0, retValue.indexOf('  ')) + 
		retValue.substring(retValue.indexOf('  ')+1, retValue.length); 
    }
    return retValue; 
}
//alert(isDate("2007-11-01"));
//alert(isTel("028-85612508"));
//alert(isMobile(15902804662));
//alert(isZipCode(336000));
//alert(isEmail("jobsen123@163.com"));
//alert(isIdCard("51162119850904819X"));